package 极客算法训练营.chapter10;

public class 跳跃游戏2 {
    class Solution {
        public int jump(int[] nums) {
            int farthest = 0;
            int step = 0, start = 0, end = 0;
            while (end < nums.length - 1) {
                for (int i = start; i <= end; i++) {
                    farthest = Math.max(i + nums[i], farthest);
                }
                start = end + 1;
                end = farthest;
                step++;
            }
            return step;
        }
    }
}
